package com.teach.basic.controller;

import com.common.bean.PageVo;
import com.common.bean.QueryCondition;
import com.common.bean.Response;
import com.teach.basic.model.dto.ArticleDTO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.teach.basic.service.impl.ArticleServiceImpl;
import com.teach.basic.model.po.Article;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 文章表 前端控制器
 * </p>
 * @version 1.0
 * @author hzz
 * @since 2020-03-10
 */
@Validated
@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private ArticleServiceImpl serviceArticle;

    @GetMapping("/index")
    public String fun(HttpServletRequest request,HttpServletResponse response){
        return "ok";
    }
    /**
     * 列表
     */
    @ApiOperation("分页查询(排序)")
    @GetMapping("/list")
    public Response<PageVo> getList(@Valid QueryCondition queryCondition,Article article){
        PageVo page = serviceArticle.queryPage(queryCondition,article);
        return Response.ok(page);
    }
    /**
     * 信息
     */
    @ApiOperation("详情查询")
    @RequestMapping("/info")
    public Response<Article> info(@RequestParam("id") String id){
        Article info = serviceArticle.getById(id);
        return Response.ok(info);
    }
    @RequestMapping("/add")
    public Response<Object> add(@RequestBody(required = true) ArticleDTO article){
        return Response.ok(serviceArticle.add(article));
    }

}

